package com.sport.service.Impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.sport.entity.Sport;
import com.sport.entity.SysPermission;
import com.sport.mapper.SysPermissionMapper;
import com.sport.mapper.SysSportMapper;
import com.sport.service.SysPermissionService;
import com.sport.service.SysSportService;
import com.sport.utils.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Service;
import org.springframework.util.unit.DataUnit;

import java.util.List;

@Service
@Slf4j
public class SysSportServiceImpl implements SysSportService {
    @Autowired
    SysSportMapper sysSportMapper;
    @Override
    public Result findPage(QueryInfo queryInfo) {
        log.info("开始权限分页:--->页面{},--->页数{},查询内容{}",queryInfo.getPageNumber(),queryInfo.getPageSize(),queryInfo.getQueryString());
        PageHelper.startPage(queryInfo.getPageNumber(), queryInfo.getPageSize());
        Page<Sport> page = sysSportMapper.findPage(queryInfo.getQueryString());
        long total=page.getTotal();
        List<Sport> result=page.getResult();
        log.info("查询的总条数---->{}",total);
        log.info("分页列表——-{}",result);
        return PageResult.pageResult(total,result);
    }




    @Override
    public Result insert(Sport sport) {
        sport.setCreateName(SecurityUtil.getUsername());
       sport.setCreateName(DateUtil.getNowDateTime());
        sysSportMapper.insert(sport);
        return Result.success("数据插入成功");
    }

    @Override
    public Result delete(Long id) {
        sysSportMapper.delete(id);
        return Result.success("数据删除成功");
    }


    @Override
    public Result update(Sport sport) {
        sport.setCreateName(SecurityUtil.getUsername());
        sport.setCreateName(DateUtil.getNowDateTime());
       sysSportMapper.update(sport);
        return Result.success("数据修改成功");
    }

    @Override
    public Result findAll() {

        return Result.success("数据查询成功",sysSportMapper.findAll());
    }


}
